package net.huashitong.ssydt.provider.task.service;


import net.huashitong.ssydt.base.dao.LongMapper;
import net.huashitong.ssydt.base.service.AbstractLongService;
import net.huashitong.ssydt.provider.task.mapper.SsTaskMyCardMapper;
import net.huashitong.ssydt.task.entity.SsTaskMyCard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2018.01.10
 */
@Service
@Transactional
public class SsTaskMyCardServiceImpl extends AbstractLongService<SsTaskMyCard> implements SsTaskMyCardService {

    private SsTaskMyCardMapper mapper;

    @Autowired
    public SsTaskMyCardServiceImpl(SsTaskMyCardMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    protected LongMapper<SsTaskMyCard> getLongMapper() {
        return this.mapper;
    }

    @Override
    public SsTaskMyCard getAutoCreateByUserId(String userId) {
        SsTaskMyCard ssTaskMyCard = this.getByUserId(userId);
        if (ssTaskMyCard == null) {
            ssTaskMyCard = new SsTaskMyCard();
            ssTaskMyCard.setUserId(userId);
            ssTaskMyCard.setCardNumber(0);
            ssTaskMyCard.setAddScore(BigDecimal.valueOf(0));
            this.insert(ssTaskMyCard);
        }
        return ssTaskMyCard;
    }

    @Override
    public SsTaskMyCard getByUserId(String userId) {
        return this.mapper.getByUserId(userId);
    }
}
